#!/bin/sh
# Set up GTK+ build environment on Windows

PRGNAM=gtk+-bundle
VERSION=${VERSION:-2.22.1}
MINOR=${MINOR:-20101227_win32}

SRCDIR=$(cd $(dirname $0); pwd)

case "${ARCH:-$( uname -m )}" in
  i?86) export ARCH=i386 ;;
  #x86_64) export ARCH=x86_64 ;;
  *) echo "Unspported platforms"
     exit 1
     ;;
esac

SRCNAM="${PRGNAM}_${VERSION}-${MINOR}.zip"
SOURCE="$SRCDIR/$SRCNAM"
SRCURL="http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip"

set -eu

if ! [ -f ${SOURCE} ]; then
  if [ "${SRCURL}" ]; then
    wget -T 20 -O "${SOURCE}" "${SRCURL}" || true
    if [ $? -ne 0 -o ! -s "${SOURCE}" ]; then
      echo "Fail to download '$SRCNAM'. Aborting."
      exit 1
    fi
  else
    echo "File '$SRCNAM' not available. Aborting."
    exit 1
  fi
fi

mkdir -p "${SRCDIR}/../bundle"
OUTPUT=$(cd "$SRCDIR/../bundle"; pwd)
echo $OUTPUT

unzip "$SOURCE" "bin/*" "etc/*" "include/*" "lib/*" -d "$OUTPUT"
